package com.java.admin.service.impl;

import com.java.admin.service.ProductService;
import com.java.clients.ProductClient;
import com.java.clients.SearchClient;
import com.java.param.AdminProductParam;
import com.java.param.ProductIdRemoveParam;
import com.java.param.ProductSearchParam;
import com.java.pojo.Product;
import com.java.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ProductServiceImpl implements ProductService {

    @Autowired
    private SearchClient searchClient;

    @Autowired
    private ProductClient productClient;
    /**
     * 根据关键字搜索商品信息
     *
     * @param productSearchParam
     * @return
     */
    @Override
    public R list(ProductSearchParam productSearchParam) {

        R r = searchClient.search(productSearchParam);
        log.info("ProductServiceImpl.list 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 添加商品信息
     *
     * @param adminProductParam
     * @return
     */
    @Override
    public R save(AdminProductParam adminProductParam) {
        R r = productClient.adminSave(adminProductParam);
        log.info("ProductServiceImpl.save 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 更新商品信息
     *
     * @param product
     * @return
     */
    @Override
    public R update(Product product) {
        R r = productClient.adminUpdate(product);
        log.info("ProductServiceImpl.update 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 删除商品信息
     *
     * @param productIdRemoveParam
     * @return
     */
    @Override
    public R remove(ProductIdRemoveParam productIdRemoveParam) {

        R r = productClient.adminRemove(productIdRemoveParam);
        log.info("ProductServiceImpl.remove 业务已经完成,结果:{}", r);
        return r;
    }
}
